﻿/*
 * Created by SharpDevelop.
 * User: Intel
 * Date: 14.11.2014
 * Time: 9:33
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
namespace Region
{
  
  /// <summary>
  /// Description of UserSelector.
  /// </summary>
  public partial class UserSelector :  UserControl
  {
    UserSelectorForm form;
    protected Engine m_engine;
    protected UserList m_userList; 
    protected Int32 m_UserID = 218;
    public Engine engine{get{return m_engine;}set{m_engine=value;onchange();}}
    public UserList userList{get{return m_userList;}set{m_userList=value;onchange();}}
    public Int32 UserID{get{return m_UserID;}set{m_UserID=value;onchange();}}
    public delegate void EventHandlerOnSelectUser(Int32 UserID);    
    public event EventHandlerOnSelectUser OnSelectUser;
    protected void onchange()
    {
      if (m_engine==null) return;
      form.engine = m_engine;
      form.userList = m_userList;
      form.UserID = m_UserID;
      button1.Text = (m_UserID>0)?m_engine.getUser(m_UserID).FIO:"[не выбран]";
    }
    protected void changeUserID(Int32 UserID)
    {
      if (m_UserID == UserID) return;
      m_UserID = UserID;
      button1.Text = (m_UserID>0)?m_engine.getUser(m_UserID).FIO:"[не выбран]";  
      if (OnSelectUser!=null) 
        OnSelectUser(m_UserID);      
    }
    public UserSelector()
    {
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      //
      // TODO: Add constructor code after the InitializeComponent() call.
      //
      form = new UserSelectorForm();
      form.OnSelectUser += changeUserID;
    }
		void Button1Click(object sender, EventArgs e)
		{
		  if (userList==null) userList = new UserList(engine);
		  form.Location = this.PointToScreen(new Point(0,this.Height));
		  form.ShowList();
		  //form.Location = this.PointToScreen(new Point(0,this.Height));
		    return;
		}

    
  }
}
